﻿using StubWebsite;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using jTest;

namespace StubWebsite.FunctionalTests
{
    
    
    /// <summary>
    ///This is a test class for SampleWebFormTest and is intended
    ///to contain all SampleWebFormTest Unit Tests
    ///</summary>
	[TestClass()]
	public class jTest_Test
	{
		/// <summary>
		/// The relitive path the the Stub Site.
		/// </summary>
		private const string WebsiteLocation = "..\\..\\..\\..\\..\\..\\Source\\jWebTest\\StubWebsite";

		private TestContext _testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return _testContextInstance;
			}
			set
			{
				this._testContextInstance = value;
			}
		}

		#region jTest HasAttr

		/// <summary>
		/// Test result.HasTag with a single h1.
		/// </summary>
		[TestMethod()]
		[AspNetDevelopmentServer("StubWebsite", jTest_Test.WebsiteLocation)]		
		public void jTest_HasAttr_SimpleTest()
		{
			// <div class="nestedContainer">
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
				 .HasAttr(".nestedContainer", "class", "nestedContainer", "Has class nestedContainer.");
		}

		#endregion

		#region jTest HasTag
		/// <summary>
		/// Test result.HasTag with a single h1.
		/// </summary>
		[TestMethod()]
		[AspNetDevelopmentServer("Sample", jTest_Test.WebsiteLocation)]
		public void jTest_HasTag_SimpleTest()
		{
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
				 .HasTag("h1", 1, "Has a title");
		}


		/// <summary>
		/// Test the number of divs in the page.
		///</summary>
		[TestMethod()]
		[AspNetDevelopmentServer("Sample", jTest_Test.WebsiteLocation)]
		public void jTest_HasTag_MultipleResultTest()
		{
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
				 .HasTag("div", 3, "Invaid div count");
		}

		#endregion

		#region jTest HasVal
		/// <summary>
		///A test for HasVal
		///</summary>
		[TestMethod()]
		[AspNetDevelopmentServer("Sample", jTest_Test.WebsiteLocation)]
		public void jTest_HasVal_SimpleTest()
		{
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
				 .HasVal("h1", "Test WebForm", "Title has a value.");
		}

		/// <summary>
		///A test for HasVal
		///</summary>
		[TestMethod()]
		[AspNetDevelopmentServer("Sample", jTest_Test.WebsiteLocation)]
		public void jTest_HasVal_ComplexSelectorTest()
		{
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
				 .HasVal("div h3", "Nested Item", "Title has a value.");
		}
		#endregion

		#region jTest NoAttr
		/// <summary>
		/// Test result.HasTag with a single h1.
		/// </summary>
		[TestMethod()]
		[AspNetDevelopmentServer("StubWebsite", jTest_Test.WebsiteLocation)]		
		public void jTest_NoAttr_SimpleTest()
		{
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
				 .NoAttr(".nestedContainer", "class", "bad value", "Has bad value.");
		}
		#endregion

		#region jTest NoVal
		/// <summary>
		///A test for HasVal
		///</summary>
		[TestMethod()]
		[AspNetDevelopmentServer("StubWebsite", jTest_Test.WebsiteLocation)]		
		public void jTest_NoVal_SimpleTest()
		{			
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
						 .NoVal("h1", "Bad value", "Bad value is not a valid value.");
		}		
		#endregion

		#region jTest NoVal
		/// <summary>
		///A test for HasVal
		///</summary>
		[TestMethod()]
		[AspNetDevelopmentServer("StubWebsite", jTest_Test.WebsiteLocation)]		
		public void jTest_NoTag_BadSelectorTest()
		{
			jTestDocument.Test("SampleWebForm.aspx", this.TestContext)
				 .NoTag("p1", "Invalid selector");
		}
		#endregion

		#region jTest Combinations

		/// <summary>
		/// Perform a series of tests on a rendered page using jQuery
		/// </summary>
		[AspNetDevelopmentServer("StubWebsite", 
								 jTest_Test.WebsiteLocation)]
		public void jTest_Combination_Test()
		{
			// Download a page.
			jTestDocument target = 
				jTestDocument.Test("SampleWebForm.aspx", 
								   this.TestContext);

			// Always have a negitive test first
			target.NoTag("p1", "Invalid selector allowed");

			// Find check how many divs we have
			target.HasTag("div", 3, "Invaid div count"); 
			
			// Test the value of the page headline
			target.NoVal("h1", 
						"Bad value", 
						"Bad value is not a valid value.");

			// Lets try a really complex selector
			target.HasAttr("#form1 div.nestedContainer", 
						   "class", 
						   "nestedContainer", 
						   "Has class nestedContainer.");
		}

		[TestMethod()]
		[AspNetDevelopmentServer("Sample", jTest_Test.WebsiteLocation)]
		public void jTest_Combination_RepeatTest()
		{
			jTestDocument target = jTestDocument.Test("SampleWebForm.aspx", this.TestContext);
			target.NoTag("p1", "Invalid selector");
			target.HasTag("div", 3, "Invaid div count");
			target.NoVal("h1", "Bad value", "Bad value is not a valid value.");
		}

		
		#endregion

	}
}
